<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>系统角色配置</title>
    <%@include file="/WEB-INF/jsp/common/meta2.jsp" %>
</head>
<body class="content-body">
<div class="container-fluid">

    <table class="table table-responsive table-bordered">
        <tr>
            <th colspan="20" class="bg-info text-center">表单编辑</th>
        </tr>
        <tr>
            <td>
                <form id="inputForm" action="${ctx}/common/role/save" method="post"
                      class="form-horizontal col-sm-offset-2 col-sm-8" role="form">
                    <input name="id" value="${entity.id}" id="id" type="hidden"/>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">角色名称：</label>

                        <div class="col-sm-4">
                            <input type="text" name="name" id="name"
                                   value="${entity.name}" placeholder="角色名称" class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">角色编码：</label>

                        <div class="col-sm-4">
                            <input type="text" name="code" id="code" value="${entity.code}" placeholder="角色编码"
                                   class="form-control input-sm">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">禁用：</label>

                        <div class="col-sm-8">

                            <label class="radio-inline">
                                <input type="radio" name="enable" value="true" ${entity.enable? 'checked':''}> 是
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="enable" value="false" ${entity.enable? '':'checked'}> 否
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">权限范围：</label>

                        <div class="col-sm-8">


                            <c:forEach items="${groups}" var="group">
                                <div class="well-sm well">
                                    <span class="glyphicon ${group.icon == "" || group.icon == null? "glyphicon-folder-close":group.icon}"></span>
                                        ${group.name}

                                    <div>
                                        <c:forEach items="${resources}" var="resource">
                                            <c:if test="${resource.groupId == group.id}">
                                                <input type="checkbox" name="scope"
                                                       value="${resource.id}"/>
                                                ${resource.name}
                                            </c:if>
                                        </c:forEach>
                                    </div>
                                </div>
                            </c:forEach>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">备注：</label>

                        <div class="col-sm-8">
                            <textarea class="form-control" rows="8" name="memo">${entity.memo}</textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-4 col-sm-8">
                            <input type="submit" value="确定" class="btn btn-info btn-sm">
                            <input class="btn btn-warning btn-sm" onclick="history.go(-1);" type="button"
                                   value="返回"/>
                        </div>
                    </div>


                </form>

            </td>
        </tr>
    </table>
</div>

</body>
</html>

<script>
    $(function () {
        $("#inputForm").validate({
            rules: {
                order: {
                    digits: true
                },
                url: {
                    required: true
                },
                scope: {
                    required: true
                },
                code: {
                    required: true,
                    maxlength: 30,
                    remote: {
                        type: "POST",
                        url: "${ctx}/common/role/repeat/code",
                        beforeSend: function (xhr) {
                            top.loadingModal.stop = true;
                        },
                        complete: function (xhr, status) {
                            top.loadingModal.stop = false;
                        },
                        data: {
                            id: $("#id").val(),
                            code: function () {
                                return $("#code").val().trim();
                            }
                        }
                    }
                },
                schoolId: {
                    required: true
                },
                collegeId: {
                    required: true
                },
                name: {
                    required: true,
                    maxlength: 30
                },
                memo: {
                    maxlength: 500
                }
            },
            messages: {
                code: {
                    remote: "角色编码重复！"
                }
            }
        });

        var scopes = "${entity.scope}";
        scopes = scopes.split(",");
        for (var s in scopes) {
            var rid = scopes[s];
            $("input[value=" + rid + "]")[0].checked = true;
        }
    });


</script>
